In probability theory and statistics, variance is the expected value of the squared deviation from the mean of a random variable. The standard deviation (SD) is obtained as the square root of the variance. Variance is a measure of dispersion, meaning it is a measure of how far a set of numbers is spread out from their average value. It is the second central moment of a distribution, and the covariance of the random variable with itself, and it is often represented by , , , , or .
An advantage of variance as a measure of dispersion is that it is more amenable to algebraic manipulation than other measures of dispersion such as the expected absolute deviation; for example, the variance of a sum of uncorrelated random variables is equal to the sum of their variances. A disadvantage of the variance for practical applications is that, unlike the standard deviation, its units differ from the random variable, which is why the standard deviation is more commonly reported as a measure of dispersion once the calculation is finished. Another disadvantage is that the variance is not finite for many distributions.
There are two distinct concepts that are both called "variance". One, as discussed above, is part of a theoretical probability distribution and is defined by an equation. The other variance is a characteristic of a set of observations. When variance is calculated from observations, those observations are typically measured from a real-world system. If all possible observations of the system are present, then the calculated variance is called the population variance. Normally, however, only a subset is available, and the variance calculated from this is called the sample variance. The variance calculated from a sample is considered an estimate of the full population variance. There are multiple ways to calculate an estimate of the population variance, as discussed in the section below.
The two kinds of variance are closely related. To see how, consider that a theoretical probability distribution can be used as a generator of hypothetical observations. If an infinite number of observations are generated using a distribution, then the sample variance calculated from that infinite set will match the value calculated using the distribution's equation for variance. Variance has a central role in statistics, where some ideas that use it include descriptive statistics, statistical inference, hypothesis testing, goodness of fit, and Monte Carlo sampling.
Definition
The variance of a random variable
is the
expected value of the squared deviation from the mean of
,
:
This definition encompasses random variables that are generated by processes that are discrete, continuous, neither, or mixed. The variance can also be thought of as the
covariance of a random variable with itself:
The variance is also equivalent to the second cumulant of a probability distribution that generates . The variance is typically designated as , or sometimes as or , or symbolically as or simply (pronounced "sigma squared"). The expression for the variance can be expanded as follows:
In other words, the variance of is equal to the mean of the square of minus the square of the mean of . This equation should not be used for computations using floating-point arithmetic, because it suffers from catastrophic cancellation if the two components of the equation are similar in magnitude. For other numerically stable alternatives, see algorithms for calculating variance.
Discrete random variable
If the generator of random variable
is discrete with probability mass function
, then
where is the expected value. That is,
(When such a discrete weighted variance is specified by weights whose sum is not 1, then one divides by the sum of the weights.)
The variance of a collection of equally likely values can be written as
where is the average value. That is,
The variance of a set of equally likely values can be equivalently expressed, without directly referring to the mean, in terms of squared deviations of all pairwise squared distances of points from each other:
Absolutely continuous random variable
If the random variable
has a probability density function
, and
is the corresponding cumulative distribution function, then
or equivalently,
where is the expected value of given by
In these formulas, the integrals with respect to and
are Lebesgue and Lebesgue–Stieltjes integrals, respectively.
If the function is Riemann-integrable on every finite interval then
where the integral is an improper Riemann integral.
Examples
Exponential distribution
The exponential distribution with parameter > 0 is a continuous distribution whose probability density function is given by
on the interval . Its mean can be shown to be
Using integration by parts and making use of the expected value already calculated, we have:
Thus, the variance of is given by
Fair die
A fair
dice can be modeled as a discrete random variable, , with outcomes 1 through 6, each with equal probability 1/6. The expected value of is
Therefore, the variance of is
The general formula for the variance of the outcome, , of an die is
Commonly used probability distributions
The following table lists the variance for some commonly used probability distributions.
|
|
Binomial distribution | |
! |
Geometric distribution | |
! |
Normal distribution | |
! |
Uniform distribution (continuous) |
|
! |
Exponential distribution | |
! |
Poisson distribution | |
! |
Properties
Basic properties
Variance is non-negative because the squares are positive or zero:
The variance of a constant is zero.
Conversely, if the variance of a random variable is 0, then it is almost surely a constant. That is, it always has the same value:
Issues of finiteness
If a distribution does not have a finite expected value, as is the case for the Cauchy distribution, then the variance cannot be finite either. However, some distributions may not have a finite variance, despite their expected value being finite. An example is a Pareto distribution whose
Pareto index satisfies
Decomposition
The general formula for variance decomposition or the law of total variance is: If
and
are two random variables, and the variance of
exists, then
The conditional expectation of given , and the conditional variance may be understood as follows. Given any particular value y of the random variable Y, there is a conditional expectation given the event Y = y. This quantity depends on the particular value y; it is a function . That same function evaluated at the random variable Y is the conditional expectation
In particular, if is a discrete random variable assuming possible values with corresponding probabilities , then in the formula for total variance, the first term on the right-hand side becomes
where . Similarly, the second term on the right-hand side becomes
where and . Thus the total variance is given by
A similar formula is applied in analysis of variance, where the corresponding formula is
here refers to the Mean of the Squares. In linear regression analysis the corresponding formula is
This can also be derived from the additivity of variances, since the total (observed) score is the sum of the predicted score and the error score, where the latter two are uncorrelated.
Similar decompositions are possible for the sum of squared deviations (sum of squares, ):
Calculation from the CDF
The population variance for a non-negative random variable can be expressed in terms of the cumulative distribution function
F using
This expression can be used to calculate the variance in situations where the CDF, but not the density, can be conveniently expressed.
Characteristic property
The second moment of a random variable attains the minimum value when taken around the first moment (i.e., mean) of the random variable, i.e.
. Conversely, if a continuous function
satisfies
for all random variables
X, then it is necessarily of the form
, where . This also holds in the multidimensional case.
Units of measurement
Unlike the expected absolute deviation, the variance of a variable has units that are the square of the units of the variable itself. For example, a variable measured in meters will have a variance measured in meters squared. For this reason, describing data sets via their standard deviation or root mean square deviation is often preferred over using the variance. In the dice example the standard deviation is , slightly larger than the expected absolute deviation of 1.5.
The standard deviation and the expected absolute deviation can both be used as an indicator of the "spread" of a distribution. The standard deviation is more amenable to algebraic manipulation than the expected absolute deviation, and, together with variance and its generalization covariance, is used frequently in theoretical statistics; however the expected absolute deviation tends to be more robust as it is less sensitive to arising from measurement anomalies or an unduly heavy-tailed distribution.
Propagation
Addition and multiplication by a constant
Variance is invariant with respect to changes in a location parameter. That is, if a constant is added to all values of the variable, the variance is unchanged:
If all values are scaled by a constant, the variance is scaled by the square of that constant:
The variance of a sum of two random variables is given by
where is the covariance.
Linear combinations
In general, for the sum of
random variables
, the variance becomes:
see also general Bienaymé's identity.
These results lead to the variance of a linear combination as:
If the random variables are such that
then they are said to be uncorrelated. It follows immediately from the expression given earlier that if the random variables are uncorrelated, then the variance of their sum is equal to the sum of their variances, or, expressed symbolically:
Since independent random variables are always uncorrelated (see ), the equation above holds in particular when the random variables are independent. Thus, independence is sufficient but not necessary for the variance of the sum to equal the sum of the variances.
Matrix notation for the variance of a linear combination
Define
as a column vector of
random variables
, and
as a column vector of
scalars
. Therefore,
is a linear combination of these random variables, where
denotes the
transpose of
. Also let
be the covariance matrix of
. The variance of
is then given by:
This implies that the variance of the mean can be written as (with a column vector of ones)
Sum of variables
Sum of uncorrelated variables
One reason for the use of the variance in preference to other measures of dispersion is that the variance of the sum (or the difference) of
uncorrelated random variables is the sum of their variances:
This statement is called the Bienaymé formula[Loève, M. (1977) "Probability Theory", Graduate Texts in Mathematics, Volume 45, 4th edition, Springer-Verlag, p. 12.] and was discovered in 1853.[Bienaymé, I.-J. (1853) "Considérations à l'appui de la découverte de Laplace sur la loi de probabilité dans la méthode des moindres carrés", Comptes rendus de l'Académie des sciences Paris, 37, p. 309–317; digital copy available [1] ][Bienaymé, I.-J. (1867) "Considérations à l'appui de la découverte de Laplace sur la loi de probabilité dans la méthode des moindres carrés", Journal de Mathématiques Pures et Appliquées, Série 2, Tome 12, p. 158–167; digital copy available [2][3]] It is often made with the stronger condition that the variables are independent, but being uncorrelated suffices. So if all the variables have the same variance σ2, then, since division by n is a linear transformation, this formula immediately implies that the variance of their mean is
That is, the variance of the mean decreases when n increases. This formula for the variance of the mean is used in the definition of the standard error of the sample mean, which is used in the central limit theorem.
To prove the initial statement, it suffices to show that
The general result then follows by induction. Starting with the definition,
Using the linearity of the expectation operator and the assumption of independence (or uncorrelatedness) of X and Y, this further simplifies as follows:
Sum of correlated variables
Sum of correlated variables with fixed sample size
In general, the variance of the sum of variables is the sum of their
:
(Note: The second equality comes from the fact that .)
Here, is the covariance, which is zero for independent random variables (if it exists). The formula states that the variance of a sum is equal to the sum of all elements in the covariance matrix of the components. The next expression states equivalently that the variance of the sum is the sum of the diagonal of covariance matrix plus two times the sum of its upper triangular elements (or its lower triangular elements); this emphasizes that the covariance matrix is symmetric. This formula is used in the theory of Cronbach's alpha in classical test theory.
So, if the variables have equal variance σ2 and the average correlation of distinct variables is ρ, then the variance of their mean is
This implies that the variance of the mean increases with the average of the correlations. In other words, additional correlated observations are not as effective as additional independent observations at reducing the standard error. Moreover, if the variables have unit variance, for example if they are standardized, then this simplifies to
This formula is used in the Spearman–Brown prediction formula of classical test theory. This converges to ρ if n goes to infinity, provided that the average correlation remains constant or converges too. So for the variance of the mean of standardized variables with equal correlations or converging average correlation we have
Therefore, the variance of the mean of a large number of standardized variables is approximately equal to their average correlation. This makes clear that the sample mean of correlated variables does not generally converge to the population mean, even though the law of large numbers states that the sample mean will converge for independent variables.
Sum of uncorrelated variables with random sample size
There are cases when a sample is taken without knowing, in advance, how many observations will be acceptable according to some criterion. In such cases, the sample size is a random variable whose variation adds to the variation of , such that,
[Cornell, J R, and Benjamin, C A, Probability, Statistics, and Decisions for Civil Engineers, McGraw-Hill, NY, 1970, pp.178-9.]
which follows from the law of total variance.
If has a Poisson distribution, then with estimator = . So, the estimator of becomes , giving
(see standard error of the sample mean).
Weighted sum of variables
The scaling property and the Bienaymé formula, along with the property of the
covariance jointly imply that
This implies that in a weighted sum of variables, the variable with the largest weight will have a disproportionally large weight in the variance of the total. For example, if X and Y are uncorrelated and the weight of X is two times the weight of Y, then the weight of the variance of X will be four times the weight of the variance of Y.
The expression above can be extended to a weighted sum of multiple variables: